package com.brsya.movie.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

import com.brsya.base.util.UiUtil;


/**
 * Created by Brsya
 * CreateDate: 2022/3/24  17:18
 * Description:
 * 首页Tab
 */
public class TabLinearLayout extends LinearLayout {
    private AppCompatImageView iconView;
    private TextView textView;

    /**
     * 图片资源地址
     */
    private int iconResId;
    /**
     * 选中图片资源地址
     */
    private int iconCheckResId;
    /**
     * 文字颜色
     */
    private int textColorUnCheck;
    /**
     * 选中文字颜色
     */
    private int textCheckColor;

    public TabLinearLayout(Context context) {
        this(context, null);
    }

    public TabLinearLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TabLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);

        iconView = new AppCompatImageView(getContext());
        addView(iconView, new LayoutParams(UiUtil.dpToPx(getContext(), 27), UiUtil.dpToPx(getContext(), 27)));


        textView = new TextView(getContext());
        textView.setTextSize(12);
        addView(textView, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    public int getIconResId() {
        return iconResId;
    }

    public void setIconResId(int iconResId) {
        this.iconResId = iconResId;
    }

    public int getIconCheckResId() {
        return iconCheckResId;
    }

    public void setIconCheckResId(int iconCheckResId) {
        this.iconCheckResId = iconCheckResId;
    }

    public int getTextColorUnCheck() {
        return textColorUnCheck;
    }

    public void setTextColorUnCheck(int textColorUnCheck) {
        this.textColorUnCheck = textColorUnCheck;
    }


    public int getTextCheckColor() {
        return textCheckColor;
    }

    public void setTextCheckColor(int textCheckColor) {
        this.textCheckColor = textCheckColor;
    }

    public void setChecked(boolean isCheck) {
        textView.setTextColor(isCheck ? textCheckColor : textColorUnCheck);
        iconView.setImageResource(isCheck ? iconCheckResId : iconResId);
    }

    /**
     * 设置图片
     *
     * @param resId 图片资源id
     */
    public void setImageUrl(int resId) {
        iconView.setImageResource(resId);
    }

    /**
     * 设置文字
     *
     * @param text 文字内容
     */
    public void setText(String text) {
        textView.setText(text);
    }


    /**
     * 设置文字
     *
     * @param resId 文字资源id
     */
    public void setText(int resId) {
        textView.setText(resId);
    }

    /**
     * 设置过滤色
     *
     * @param color 过滤色色值
     */
    public void setTextColor(int color) {
        textView.setTextColor(color);
    }


}
